package com.example.springstack.springboot.mongo.init.dao.impl;

import com.example.springstack.springboot.mongo.init.dao.ParametersDao;
import com.example.springstack.springboot.mongo.init.entity.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

/**
 * @author qiangfanghao
 * @date
 */
@Repository("parametersDao")
public class ParametersDaoImpl implements ParametersDao {

    @Autowired
    @Qualifier("mongoTemplateMajor")
    private MongoTemplate mongoTemplate;

    @Override
    public Parameters findOne(String id) {
        return this.mongoTemplate.findById(id,Parameters.class);
    }

    @Override
    public void save (Parameters parameters) {
        this.mongoTemplate.save(parameters);
    }

    @Override
    public Parameters findOneByName(String name) {
        Query query = Query.query(Criteria.where("name").is(name));
        return this.mongoTemplate.findOne(query, Parameters.class);
    }

}
